package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import utils.AirTransportRepositoryManager;

public class NewCityController extends AbstractController {

	private AirTransportRepositoryManager repositoryManager;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String idParam = request.getParameter("cityID");
		String nameParam = request.getParameter("cityName");

		ModelAndView mav = new ModelAndView();
		
		if (idParam != null && nameParam != null && idParam.length() > 0 && nameParam.length() > 0) {
			
			if ( repositoryManager.addNewCity(idParam, nameParam) == true ) {
				mav.addObject("cityname", nameParam);
				mav.addObject("flag", true);
			}
			else {
				mav.addObject("cityname", nameParam);
				mav.addObject("flag", false);
			}
		}

		return mav;
	}

	public AirTransportRepositoryManager getRepositoryManager() {
		return repositoryManager;
	}

	public void setRepositoryManager(AirTransportRepositoryManager repositoryManager) {
		this.repositoryManager = repositoryManager;
	}


	
}
